var mysql = require("mysql");
var pool = mysql.createPool({
  host: "localhost",
  user: "root",
  password: "plh123456",
  database: "annualmeeting",
  port: 3306,
  connectionLimit: 50,
  multipleStatements: true,
});
const query = function (sql, values) {
  return new Promise(function (resolve, reject) {
    //建立链接
    pool.getConnection(function (err, connection) {
      if (err) {
        return reject(err); // not connected!
      }
      connection.query(sql, values, function (error, results) {
        //将链接返回到连接池中，准备由其他人重复使用
        connection.release();
        if (error) {
          return reject(error);
        }
        resolve(results);
      });
    });
  });
};
module.exports = query;
